//
//  TestPageContent2VC.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/6/10.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import Foundation
import RxSwift
import JXSegmentedView
import CooperSwift

class TestPageContent2VM: NSObject, TableViewModelProtocol, UITableViewDelegate, RefreshControllable {
   
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return vm_tableView(tableView, heightForRowAt: indexPath)
    }
    
    func configDown() {
        
        let row = TestClasCellModel("测试2")
        addFirstSectionItems([TestClasCellModel("测试1").addTargetKey(bindKey()), row, TestClasCellModel("测试3")])
    }
    
    func refresh() {
        PublicMethod.delay(2) {
            self.rx.refreshStatus.onNext(.endHeaderRefresh)
        }
    }
    
    @objc func sumbit()  {
        log.debug("sumbit")
        
        guard let block = self.serviceBlock else { return }
        guard let vc = block(.controller) as? UIViewController else { return }
        vc.navigationController?.pushViewController(TestWebVC(localHtmlFileName: "test.htm"), animated: true)
  
//        var item = firstSection().items[safe: 1]
//        if item?.cellHeight == 0 {
//            item?.cellHeight = UITableView.automaticDimension
//        }else {
//            item?.cellHeight = 0
//        }
//        reloadTable()
    }
  
}

class TestPageContent2VC: UIViewController, TableEnableProtocol, Refreshable {
    
    
    let disposeBag = DisposeBag()
    
    let vm = ViewModelFactory.tableVM(TestPageContent2VM.self)
        
    override func viewDidLoad() {
        super.viewDidLoad()
        
        rx.updateRefresh(vm, scrollview: tableView, bag: disposeBag, refreshConfig: .header)
        configAll(vm, disposeBag: disposeBag)
    
    }
    
}
